package site.yunnong.atvris.portal.spider.baidu;

import com.geccocrawler.gecco.GeccoEngine;
import org.springframework.context.annotation.Bean;
import site.yunnong.atvris.portal.spider.SpringGeccoEngine;
import site.yunnong.atvris.portal.spider.SpringPipelineFactory;

/**
 * @author zjh
 * @date 2021/8/30 0:03
 */
// 需要爬虫时再开启
//@Configuration
public class BaiduBeanConfig {
    
    @Bean
    public SpringPipelineFactory springPipelineFactory() {
        return new SpringPipelineFactory();
    }
    
    @Bean
    public SpringGeccoEngine initGecco() {
        return new SpringGeccoEngine() {
            @Override
            public void init() {
                String[] urls = new String[16];
                for (int i = 1; i < 17; i++) {
                    int count = i * 10;
                    String url = "https://www.baidu.com/sf/vsearch?pd=video&tn=vsearch&lid=ffb4b36e0001af01&ie=utf-8&wd=%E6%B0%B4%E4%BA%A7%E5%85%BB%E6%AE%96&rsv_spt=7&rsv_bp=1&f=8&oq=%E6%B0%B4%E4%BA%A7%E5%85%BB%E6%AE%96&rsv_pq=ffb4b36e0001af01&rsv_t=18e9jtFwautlgnmQ3ZikTtksYo1WzQTOtkgkowxSx9n7mqIW2ZRS4lKyZyo&async=1&pn=" + count;
                    urls[i - 1] = url;
                }
                GeccoEngine.create()
                        .pipelineFactory(springPipelineFactory())
                        .classpath("site.yunnong.atvris.portal.spider.baidu")
                        .start(urls)
                        .interval(2000)
                        .start();
            }
        };
    }
}
